/**
 * Copyright (C), 2015-2019, XXX有限公司
 * FileName: CashRewardProcessor
 * Author:   zhouheng
 * Date:     2019/6/18 22:44
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.zhouh.golden.activity.service.processor.reward;

import com.zhouh.golden.activity.service.processor.AbstractRewardProcessor;
import com.zhouh.golden.activity.service.processor.ActivityDrawContext;
import com.zhouh.golden.activity.service.processor.constants.DrawContants;
import com.zhouh.golden.common.utils.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 〈一句话功能简述〉<br> 
 * 〈〉
 *
 * @author zhouheng
 * @create 2019/6/18
 * @since 1.0.0
 */
@Slf4j
@Service
public class JdCardRewardProcessor extends AbstractRewardProcessor {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Override
    protected void afterProcessor(ActivityDrawContext activityDrawContext) {
        //发送短信
        // 1.手机号码校验
        // 2. 调用短信服务发送短信
        Map<String,String> map = new HashMap<>();
        String tel = activityDrawContext.getUserQueryResponse().getMobile();
        String awardName = activityDrawContext.getActDrawAward().getAwardName();
        String endTime = DateUtil.getDateFormat(new Date(),"YYYY-MM-DD") + "00:00:00";

        map.put("mobile", tel);
        map.put("awardName",awardName);
        map.put("endTime",endTime);

        //在控制台显示一份【方便测试】
        System.out.println("用户手机号：" + tel + "获得奖品为" + awardName + "请于" + endTime + "前来获取奖品");

        rabbitTemplate.convertAndSend(DrawContants.QUEUE_NAME, map);
    }

    @Override
    public void processor(ActivityDrawContext activityDrawContext) {
        log.info("用户:{},获得奖项:{}",activityDrawContext.getActivityTurntableDrawReq().getUserId(),activityDrawContext.getActDrawAwardItem().getItemName());
        // 减库存

        // 保存数据
        saveDrawAwardRecord(activityDrawContext);
    }
}